from db import db
import datetime

class Answer(db.Model):
    __tablename__ = 'answer'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(255), nullable=False)
    answer = db.Column(db.String(1024), nullable=False)
    file_url = db.Column(db.String(255), nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)
    question_id = db.Column(db.Integer, nullable=False)
    adoption = db.Column(db.Integer, nullable=False)

    def __init__(self, username, answer, file_url, question_id,adoption=0):
        self.username = username
        self.answer = answer
        self.file_url = file_url
        self.question_id = question_id
        self.adoption = adoption

    def to_dict(self):
        return {
            'id': self.id,
            'username': self.username,
            'answer': self.answer,
            'fileUrl': self.file_url,
            'questionId': self.question_id,
            'adoption': self.adoption,
            'createTime': self.create_time
        }